package com.lqd.mall.system.controller;

import com.lqd.mall.basis.response.CommonResult;
import com.lqd.mall.basis.response.Result;
import com.lqd.mall.interaction.system.SysMenuEntity;
import com.lqd.mall.interaction.system.qo.MenuQueryQo;
import com.lqd.mall.interaction.system.vo.MenuVo;
import com.lqd.mall.interaction.system.vo.RouterVo;
import com.lqd.mall.log.annotation.Log;
import com.lqd.mall.log.enums.BusinessType;
import com.lqd.mall.security.utils.SecurityUtils;
import com.lqd.mall.system.SysMenuControllerApi;
import com.lqd.mall.system.service.ISysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 零起点
 * @create 2022-02-23 23:43
 */
@RestController
public class SysMenuController implements SysMenuControllerApi {

    @Autowired
    private ISysMenuService sysMenuService;

    @Override
    @Log(title = "查询菜单",businessType = BusinessType.OTHER )
    public Result<List<RouterVo>> getRouters() {
        Long userId = SecurityUtils.getUserId();
        List<MenuVo> menus = sysMenuService.selectMenuTreeByUserId(userId);
        return Result.SUCCESS(sysMenuService.buildMenus(menus));
    }

    @Override
    public Result<List<SysMenuEntity>> list(MenuQueryQo menuQueryQo) {
        Long userId = SecurityUtils.getUserId();
        List<SysMenuEntity> menus = sysMenuService.selectMenuList(userId,menuQueryQo);
        return Result.SUCCESS(menus);
    }

    @Override
    public Result<SysMenuEntity> findMenuById(Integer menuId) {
            SysMenuEntity entity =  sysMenuService.findMenuById(menuId);
        return entity != null?Result.SUCCESS(entity):Result.FAIL(new SysMenuEntity());
    }

    @Override
    public CommonResult sava(SysMenuEntity menu) {



        return null;
    }


}
